package com.timguan.render.dataprocessor.filter;

import com.timguan.render.dataapi.domain.CmsDataDO;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by gkq on 16/1/5.
 */
public class DataFilterChain implements DataFilter {
    List<DataFilter> dataFilterList = new ArrayList<DataFilter>();

    /**
     * 链式调用，构造filter链
     *
     * @param dataFilter
     * @return
     */
    public DataFilterChain add(DataFilter dataFilter) {
        dataFilterList.add(dataFilter);
        return this;
    }

    @Override
    public List<CmsDataDO> doFilter(List<CmsDataDO> cmsDataDOList, Map<String, String> params) {
        for (DataFilter f : dataFilterList) {
            cmsDataDOList = f.doFilter(cmsDataDOList, params);
        }
        return cmsDataDOList;
    }
}
